package cn.bdqn.controller;

import cn.bdqn.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Controller
public class HelloThmeleafController {

    @RequestMapping
    public String hello(Model model) {
        model.addAttribute("mes", "哈哈哈哈 雷光庆");
        return "/hello";
    }

    @GetMapping("/expression")
    public String expression(Model model, HttpServletRequest request, HttpSession session) {
        model.addAttribute("meg", "李四");
        model.addAttribute("user", new User(1, "忘我", "女", 19));

        request.setAttribute("username", "站了");
        session.setAttribute("username", "雷某");

        model.addAttribute("date", new Date());
        return "demo/expression";
    }

    @GetMapping("/expression2")
    public String expression2(Model model, HttpServletRequest request, HttpSession session) {

        model.addAttribute("user", new User(1, "忘我", "女", 19));


        return "demo/expression2";
    }
    @RequestMapping("/insert")
    @ResponseBody
    public User insert(User user){
        return user;
    }
    @GetMapping("/ifunelss")
    public String ifunelss(Model model){
        model.addAttribute("age",19);
        return "demo/ifunelss";
    }
    @GetMapping("/switch2")
    public String switch2(Model model){
        model.addAttribute("sex","男");
        return "demo/switch";
    }
    @GetMapping("/xun")
    public String xun(Model model){
        List<User> list=new ArrayList<>();
        list.add(new User(1,"张三","男",19));
        list.add(new User(2,"李四","女",18));
        list.add(new User(3,"王五","男人",13));
        list.add(new User(4,"赵云","高手",22));
        model.addAttribute("list",list);

        return "demo/each";
    }
    @GetMapping("/inline")
    public String inline(Model model){
        model.addAttribute("name","雷广某");
        return "demo/inline";
    }
    @RequestMapping("/zhucai")
    public String zhucai(){
        return "demo/zhucai";
    }



}
